using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using Reviewer.Business;
using Reviewer.Entities;
using Reviewer.Entities.Services;
using Reviewer.Utilities;

public partial class MasterPageV2 : System.Web.UI.MasterPage
{
    protected override void OnInit(EventArgs e)
    {
        bool IsDevMachine = false;
        if (Boolean.TryParse(ConfigurationManager.AppSettings["IsDevMachine"], out IsDevMachine) && !IsDevMachine)
        {
            if (Request.Url.Host == "reviewer.dk")
            {
                Response.Redirect("http://www.reviewer.dk" + Request.Url.PathAndQuery);
            }
        }
        base.OnInit(e);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (IFrontPageTopService service = ServiceFactory.FrontPageTopService)
            {
                List<FrontPageTop> items = service.Find(-1).ToList();
                for (int i = 0; i < 4; i++)
                {
                    items = items.Randomized().ToList();
                    FrontPageTop item = items.Take(1).First();
                    items.Remove(item);
                    CanvasTop.InnerHtml += "<div onclick=\"window.location='" + item.Link + "'\" style=\"background-image:url(/FrontBilledTop/" + item.Id + ".jpg); border:1px solid black; cursor:pointer; width:200px; height:150px; float:right;\"><img src=\"/App_Themes/RV2/Images/TopBilldShadow2.png\" height=\"150px\" alt=\""
                    + item.Title.Replace("\"", "") + "\" /></div>";
                    CanvasTopTitel.InnerHtml += "<div onclick=\"window.location='" + item.Link + "'\" class=\"PictureTopTitel\">" + item.Title + "</div>";
                    CanvasTopDesc.Text += "<div onclick=\"window.location='" + item.Link + "'\" class=\"PictureTopText\">" + item.Text + "</div>";
                }
            }
        }

        if (!Page.ClientScript.IsClientScriptIncludeRegistered("jquery-1.4.2.min.js"))
        {
            Page.ClientScript.RegisterClientScriptInclude("jquery-1.4.2.min.js", ResolveUrl("~/js/jquery-1.4.2.min.js"));
        }

        if (!Page.ClientScript.IsClientScriptIncludeRegistered("jquery-ui-1.8.4.custom.min.js"))
        {
            Page.ClientScript.RegisterClientScriptInclude("jquery-ui-1.8.4.custom.min.js", ResolveUrl("~/js/jquery-ui-1.8.4.custom.min.js"));
        }

        if (!Page.ClientScript.IsClientScriptIncludeRegistered("jquery.lightbox-0.5.min.js"))
        {
            Page.ClientScript.RegisterClientScriptInclude("jquery.lightbox.js", ResolveUrl("~/js/jquery.lightbox.js"));
            Page.ClientScript.RegisterStartupScript(typeof(System.Web.UI.WebControls.Image), "StartLightBox", @"
<script type=""text/javascript"">
    $(function () {
		$("".lightbox"").lightbox({fitToScreen: true,imageClickClose: false});
        $("".lightbox-2"").lightbox({fitToScreen: true});
		});
</script>
");
            //<script type=""text/javascript"">
            //$(function() {   
            //	$('a[rel=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
            //});
            //</script>
            //");
        }

    }
}